package coupon.controller;

import coupon.service.ICouponService;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import common.model.result.Result;
import org.springframework.web.bind.annotation.RequestParam;

@RequestMapping("/coupon")
@RestController
public class CouponController {

    @Autowired
    ICouponService couponService;

    //查询所有可领取优惠券
    @GetMapping("/all")
    public Result allCoupons(@RequestHeader("uid") Long userId) {
        return couponService.allCoupons(userId);
    }

    //获取结算页面的优惠券列表
    @GetMapping("/checkoutCouponList")
    public Result checkoutCoupons(@RequestHeader("uid") Long userId) {
        return couponService.checkoutCoupons(userId);
    }
    // 根据状态查询用户优惠券列表
    @GetMapping("/list")
    public Result listCoupons(
        @RequestHeader("uid") Long userId,
        @RequestParam("status") Integer status,
        @RequestParam("page") Integer page,
        @RequestParam("pageSize") Integer pageSize
    ) {
        return couponService.listCoupons(userId, status, page, pageSize);
    }
    // 获取用户全部优惠券
    @GetMapping("/couponList")
    public Result couponList(@RequestHeader("uid") Long userId) {
        return couponService.couponList(userId);
    }
    // 查询商铺优惠券列表
    @GetMapping("/list/shop")
    public Result listShopCoupons(@RequestHeader("uid") Long userId,@RequestParam("shopId") Long shopId) {
        return couponService.listShopCoupons(userId, shopId);
    }

    // 领取优惠券
    @PostMapping("/receive")
    public Result receiveCoupon(@RequestHeader("uid") Long userId, @RequestParam Long couponId) {
        return couponService.receiveCoupon(userId, couponId);
    }

    // 根据code查询优惠券
    @GetMapping("/code")
    public Result getCouponByCode(
        @RequestParam("couponCodes") List<String> couponCodes,
        @RequestParam("userId") Long userId,
        @RequestParam("orderNo") String orderNo
    ) {
        return couponService.getCouponByCode(couponCodes,userId,orderNo);
    }
}
